<template>
	<view>
		<view class="card between" @click="open">
			<view class="fw-b">提现到</view>
			<view class="flex align-c">
				<view v-if="card_id">{{ payName }}</view>
				<view v-else>请选择</view>
				<image src="/static/home/into-gray.png" mode="aspectFill" class="into" />
			</view>
		</view>
		
		<view class="card">
			<view class="fw-b">提现金额</view>
			<view class="flex align-c card_input">
				<view class="input_util fw-b">￥</view>
				<input type="number" class="card_input_box" v-model="money" :placeholder="`可提现：￥${canTopUp ? canTopUp : '0.00'}`"
					placeholder-class="p-c" />
			</view>
			<view class="flex-center">
				<view class="submitBtn flex" @click="confirmTopUp">确认提现</view>
			</view>
		</view>
		
		<u-popup :show="show" :round="10" mode="bottom"  @close="close" @open="open">
			<view class="pop_box">
				<view class="pop_tit">
					<view class="">选择提现账号</view>
					<image src="/static/home/close-img.png" mode="aspectFill" class="close_img" />
				</view>
				<view class="flex align-c type_item" v-for="(v,i) in payList" :key="i" @click="checkItem(i)">
					<image :src="`/static/mine/${v.type == '支付宝'?'zfb':'bank'}.png`" mode="widthFix" class="icon" />
					<view class="f1 flex align-c type_item_info">
						<view class="f1">{{ v.type == '支付宝' ? v.account:`${v.card_type}（${v.card_code.substr(-4)}）` }}</view>
						<image :src="`/static/mine/${v.isCheck?'check-act':'check-none'}.png`" mode="widthFix" class="check_box" />
						<!-- <image src="/static/home/into-gray.png" mode="widthFix" class="into" /> -->
					</view>
				</view>
				<view class="flex align-c type_item" @click="$to('/pages/mine/add_account')">
					<view class="wallet_box">
						<image src="/static/mine/wallet.png" mode="widthFix" class="wallet_icon" />
					</view>
					<view class="f1 flex align-c type_item_info">
						<view class="f1">添加新账号</view>
						<image src="/static/home/into-gray.png" mode="widthFix" class="into" />
					</view>
				</view>
			</view>
			
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				money: '',
				show: false,
				payList: [],
				card_id: '',
				payIndex: '',
				payName: '',
				shop_id: '',
				canTopUp: 0.00,
			}
		},
		onLoad(opt) {
			this.canTopUp = opt.num;
			this.getAccountList();
			
		},
		onShow() {
			this.shop_id = uni.getStorageSync('shopId');
		},
		methods: {
			async getAccountList() {
				let res = await this.$api.get('staff/account/list');
				if(res.code == 200) {
					var arr = res.data;
					arr.forEach(v => {
						v.isCheck = false;
					})
					this.payList = arr;
				}
			},
			open() {
				this.show = true;
			},
			close() {
				this.show = false;
			},
			checkItem(i) {
				this.payList.forEach(v => {
					v.isCheck = false;
				});
				this.payIndex = i;
				this.card_id = this.payList[i].id;
				this.payName = this.payList[i].type== '支付宝'?'支付宝' : `${this.payList[i].card_type}（${this.payList[i].card_code.substr(-4)}）`
				this.payList[i].isCheck = true;
				this.show = false;
			},
			async confirmTopUp() {
				if(!this.card_id) {
					this.toast('请选择提现账户');
					return false;
				}
				if(!this.money) {
					this.toast('请输入提现金额');
					return false;
				}
				if(this.money > this.canTopUp) {
					this.toast('余额不足');
					return false;
				}
				let res = await this.$api.post('staff/account/cash',{
					commission: this.money,
					card_id: this.card_id,
					shop_id: this.shop_id,
				});
				if(res.code == 200) {
					uni.showToast({
						title: res.msg
					});
					setTimeout(v => {
						uni.navigateBack()
					},2500)
				}
			}
		}
	}
</script>

<style>
	page {
		background: #F7F7F7;
		padding: 30rpx;
	}
	.p-c {
		font-size: 29rpx;
		font-weight: normal;
	}
</style>
<style lang="scss" scoped>
	.submitBtn {
		width: 400rpx;
		margin: 70rpx auto;
		margin-bottom: 0;
		color: #fff;
		font-size: 32rpx;
		background: #F17816;
		border-radius: 50rpx;
		padding: 20rpx 0;
		justify-content: center;
	}

	.card {
		background: #fff;
		padding: 24rpx 27rpx;
		font-size: 27rpx;
		border-radius: 20rpx;
		margin-bottom: 60rpx;
		&_input {
			margin-top: 60rpx;
			border-bottom: 1px solid #F5F5F5;
			&_box {
				font-size: 46rpx;
				margin-left: 20rpx;
				font-weight: bold;
			}
			.input_util {
				font-size: 40rpx;
			}
		}
	}

	.pop_box {
		padding-bottom: 20rpx;
		.pop_tit {
			text-align: center;
			font-size: 27rpx;
			line-height: 80rpx;
			position: relative;
			.close_img {
				position: absolute;
				right: 40rpx;
				top: 30rpx;
				width: 25rpx;
				height: 25rpx;
			}
		}
		.type_item {
			padding: 0 40rpx;
			font-size: 29rpx;
			.type_item_info {
				height: 120rpx;
				border-bottom: 1rpx solid #F5F5F5;
				margin-left: 20rpx;
			}
			.wallet_icon {
				width: 36rpx;
				height: 29rpx;
				// margin-right: 20rpx;
			}
			.icon{
				width: 53rpx;
				height: 53rpx;
				// margin-right: 20rpx;
			}
			.wallet_box {
				padding: 10rpx;
			}
			.check_box {
				width: 43rpx;
				height: 43rpx;
			}
		}
	}
	
	.into {
		width: 12rpx;
		height: 20rpx;
		margin-left: 10rpx;
	}
</style>
